# -*- coding: utf-8 -*-
"""
决策树解决回归问题
Created on Fri Apr 27 20:08:34 2018

@author: Allen
"""
import numpy as np
import matplotlib.pyplot as plt

from sklearn import datasets
boston = datasets.load_boston()
X = boston.data
y = boston.target

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split( X, y, random_state = 666 )

from sklearn.tree import DecisionTreeRegressor
dt_reg = DecisionTreeRegressor()
dt_reg.fit( X_train, y_train )
print( dt_reg.score( X_test, y_test ) ) # 0.590217323129
print( dt_reg.score( X_train, y_train ) ) # 1.0
'''
在测试数据集上出现了百分百，说明是过拟合了。
也就是说，决策树很容易产生过拟合的。
'''